package itheima_3;

public class ArrayDemo {
    public static void main(String[] args) {
        int[] arr = {90, 20, 48, 13, 55};
        System.out.println("排序前：" + arrayToString(arr));

        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        System.out.println("排序后：" + arrayToString(arr));
    }

    public static String arrayToString(int[] arr) {
        StringBuilder arrString = new StringBuilder();
        arrString.append("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                arrString.append(arr[i]);
            } else {
                arrString.append(arr[i]).append(",");
            }
        }
        arrString.append("]");
        return arrString.toString();
    }
}
